package com.springboot.cloud.seckill.service.impl;

import com.springboot.cloud.seckill.dao.SeckillRepository;
import com.springboot.cloud.seckill.entity.SeckillActivity;
import com.springboot.cloud.seckill.service.ISeckillAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author godyao
 * @date 2022/3/26
 */
@Service
public class ISeckillAdminServiceImpl implements ISeckillAdminService {
    @Autowired
    private SeckillRepository seckillRepository;

    @Override
    public SeckillActivity addActivity(SeckillActivity seckillActivity) {
        return seckillRepository.save(seckillActivity);
    }

    @Override
    public SeckillActivity updateActivity(SeckillActivity seckillActivity) {
        return seckillRepository.save(seckillActivity);
    }

    @Override
    public Optional queryActivityById(Long id) {
        return seckillRepository.findById(id);
    }

    @Override
    public Page<SeckillActivity> queryActivity(PageRequest pageRequest) {
        return seckillRepository.findAll(pageRequest);
    }

    @Override
    public void deleteActivity(Long id) {
        seckillRepository.deleteById(id);
    }
}
